package com.gin.supermarket_inventory_system.inventory.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.gin.database.base.BasePo;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.Comment;

/**
 * 库存基本信息
 * @since : 2023/10/8 17:55
 * @author : ginstone
 * @version : v1.0.0
 **/
@Getter
@Setter
@TableName(value = InventoryPo.TABLE_NAME, autoResultMap = true)
@Entity(name = InventoryPo.TABLE_NAME)
@NoArgsConstructor
@Table(indexes = {
        @Index(columnList = "barcode"),
}, uniqueConstraints = {
        // 名称，规格，商品信息不能重复
        @UniqueConstraint(columnNames = {"name", "spec", "commodityId"})
})
public class InventoryPo extends BasePo {
    protected static final String TABLE_NAME = "tb_inventory_entity_info";

    @Column(nullable = false)
    @Comment("名称")
    String name;

    @Column(nullable = false, length = 20)
    @Comment("规格")
    String spec;

    @Column(nullable = false, length = 50, unique = true)
    @Comment("条码")
    String barcode;

    @Column(nullable = false, scale = 2)
    @Comment("零售价")
    Double price;

    @Column(nullable = false)
    @Comment("商品信息ID")
    Long commodityId;

    @Column(nullable = false)
    @Comment("库存数量")
    Integer amount;


    public InventoryPo(long id, int amount) {
        setId(id);
        this.amount = amount;
    }
}